#include "StdAfx.h"
#include <exception>
#include <string>
#include <sstream>
#include ".\exceptiondef.h"

using namespace std;

CExceptionBase::CExceptionBase( const std::string &msg /*= ""*/ ) throw()
:m_strDetailInfo(msg)
,m_strFileName("<Unknow File>")
,m_strFuncName("<Unknow Function>")
,m_iLineNumber(-1)
{

}

void CExceptionBase::Init( const char * pszFileName,const char *pszFuncName,int iLine,int iErrorCode )
{
	m_strFileName = pszFileName;
	m_strFuncName = pszFuncName;
	m_iLineNumber = iLine;
	m_iErrorCode  = iErrorCode;
}

const std::string CExceptionBase::ToString() const
{
	if (m_strExceptionInfo.empty())
	{
		stringstream strException("");
		if (!GetMessage().empty())
		{
			strException <<"Exception:" << GetMessage()<<"ErrorCode:"<<GetErrorCode();
			if (m_iLineNumber > 0)
			{
				strException << "(";
				strException << "FileName:"<<m_strFileName;
				strException << "FuncName:" << m_strFuncName;
				strException << "LineNum :" <<m_iLineNumber;
				strException << ")";
			}
		}
		m_strExceptionInfo =  strException.str();
	}
	return m_strExceptionInfo;
}


CExceptionDerived::CExceptionDerived( const std::string msg /*= ""*/ ) throw()
:CExceptionBase(msg)
{

}
